package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */

    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    @Options(useGeneratedKeys = true, keyProperty = "id" )  // 执行insert语句后会获取自增长主键值并赋值给参数对象Dish的id属性
    @AutoFill(OperationType.INSERT)
    @Insert("insert into dish (name, category_id, price, image, description, status, create_time, " +
            "update_time, create_user, update_user, make_time) " +
            "values (#{name}, #{categoryId}, #{price}, #{image}," +
            " #{description}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}, #{makeTime})")
    void insertDish(Dish dish);

    /**
     * 分页查询菜品
     * @param dishDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishDTO);

    /**
     * 批量删除菜品
     * @param ids
     */
    void deleteByIds(Long[] ids);

    /**
     * 根据id和状态查询菜品
     * @param ids
     * @param status
     * @return
     */
    Integer selectCountByIdsAndStatus(@Param("ids") Long[] ids,
                                      @Param("status") Integer status);
}
